package com.example.rabbitmq.example.rabbitmq.work;

import com.rabbitmq.client.*;

import java.io.IOException;

public class WorkQueueConsumer {

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new  ConnectionFactory();
        //%2f 是虚拟主机 /
        factory.setUri("amqp://admin:admin@192.168.1.3:5672/%2f");
        final Connection connection = factory.newConnection();
        final Channel channel = connection.createChannel();

        channel.queueDeclare("queue1", true, false,false, null);
        channel.basicConsume("queue1", new DeliverCallback() {
            @Override
            public void handle(String consumerTag, Delivery message) throws IOException {
                System.out.println(consumerTag);
                System.out.println(new String(message.getBody()));
            }
        }, new CancelCallback() {
            @Override
            public void handle(String consumerTag) throws IOException {

            }
        });
    }
}
